<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  <%String contextPath=request.getContextPath();
    %>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Signin Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="${pageContext.request.contextPath }/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->

    <!-- Custom styles for this template -->
    <link href="${pageContext.request.contextPath }/dist/css/signin.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="container">
      <form class="form-signin" action="${pageContext.request.contextPath }/UsersController?op=register" method="post" id="regForm" enctype="multipart/form-data">
        <h2 class="form-signin-heading">请注册</h2>
        
        <input type="text" id="userName" class="form-control" name="userName" placeholder="请输入用户名" required autofocus >
        <!-- 显示用户名的提示 -->
        <label id="userNameId" ></label>
        <label for="userPwd" class="sr-only">Password</label>
        <input type="password" id="userPwd" class="form-control" name="userPwd" placeholder="请输入密码" required  >
         <!-- 密码的提示 -->
        <label id="userPwdId" ></label>
        <input type="password" id="userRePwd" class="form-control" name="userRePwd" placeholder="确认密码" required  >
        <!-- 确认密码的提示 -->
        <label id="userRePwdId" ></label>
        <input type="file" id="userImg" name="userImg"  class="form-control"/>
         <label ></label>
        <button class="btn btn-lg btn-primary btn-block" type="submit">注册</button>
      </form>

    </div> <!-- /container -->


  
  </body>
  	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
  	<script type="text/javascript">
  	   $(function(){
  		  //失去焦点时触发
  		 $("#userName").blur(function(){
  			 //判断用户名是否为空
    		   if( $("#userName").val().trim()==""){
    			  $("#userNameId").text("用户名不能为空");
    		   }else{
    			   //发送ajax 用户名进行ajax验证是否可用
    			 /*   $.ajax({
    				   type:"POST",
    				   url:"${pageContext.request.contextPath }/UsersController",
    				   contentType:"application/x-www-form-urlencoded",
    				   data:{uname: $("#userName").val(),op:"checkName"},
    				   dataType:"text",
    				   success:function(data){
    					 $("#userNameId").text(data); 
    				   }
    				   
    			   }) */
    			   $.post("${pageContext.request.contextPath }/UsersController",{uname: $("#userName").val(),op:"checkName"},function(data){
    				   //把返回来的数据显示在提示标签上
    				   $("#userNameId").text(data); 
    			   })
    			   
    		   }
  		 });
  		  //判断密码  >6 不能包含空格
  		  $("#userPwd").blur(function(){
  			  if( $("#userPwd").val().trim().length>=6  &&  $("#userPwd").val().trim().indexOf(" ")== -1){
  				  $("#userPwdId").text("正确");
  			  }else{
  				 $("#userPwdId").text("密码长度大于6,不能包含空格");
  			  }
  		  });
  		  //验证确认密码
  		   $("#userRePwd").blur(function(){
  			 var upwd=$("#userPwd").val();
  			 var uprewd=$("#userRePwd").val();
  			 if(upwd==uprewd){
  				 $("#userRePwdId").text("两次密码一致");
  			 }else{
  				$("#userRePwdId").text("两次密码不一致"); 
  			 }
  		   });
  		  
  		  //最终的提交表单
  		  $("#regForm").submit(function(){
  			  if( $("#userNameId").text()=="可用" &&  $("#userPwdId").text()=="正确" &&  $("#userRePwdId").text()=="两次密码一致"){
  				  return true;
  			  }
  			  return false;
  		  })
  		  
  		  
  	   })
  	
  	
  	</script>
</html>
